home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / Mesa-3.0 / DEMOS / WINPOS.C < prev   
Encoding:
C/C++ Source or Header  |  1998-02-22  |  2.2 KB  |  118 lines

  1. /* $Id: winpos.c,v 3.1 1998/02/22 16:36:10 brianp Exp $ */
  2.  
  3. /*
  4.  * Example of how to use the GL_MESA_window_pos extension.
  5.  * Brian Paul   This file is in the public domain.
  6.  */
  7.  
  8.  
  9. /*
  10.  * $Log: winpos.c,v $
  11.  * Revision 3.1  1998/02/22 16:36:10  brianp
  12.  * changed image file and set unpack alignment to 1
  13.  *
  14.  * Revision 3.0  1998/02/14 18:42:29  brianp
  15.  * initial rev
  16.  *
  17.  */
  18.  
  19.  
  20. #include <math.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include "GL/glut.h"
  25.  
  26. #include "../util/readtex.c"  /* a hack, I know */
  27.  
  28.  
  29. #ifndef M_PI
  30. #  define M_PI 3.14159265
  31. #endif
  32.  
  33. #define IMAGE "girl.rgb"
  34.  
  35.  
  36.  
  37. static GLubyte *Image;
  38. static int ImgWidth, ImgHeight;
  39. static GLenum ImgFormat;
  40.  
  41.  
  42.  
  43. static void draw( void )
  44. {
  45.    GLfloat angle;
  46.    char *extensions;
  47.  
  48.    extensions = (char *) glGetString( GL_EXTENSIONS );
  49.    if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
  50.       printf("Sorry, GL_MESA_window_pos extension not available.\n");
  51.       return;
  52.    }
  53.  
  54.    glClear( GL_COLOR_BUFFER_BIT );
  55.  
  56.    for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  57.       GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  58.       GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  59.  
  60.       /* Don't need to worry about the modelview or projection matrices!!! */
  61. #ifdef GL_MESA_window_pos
  62.       glWindowPos2fMESA( x, y );
  63. #endif
  64.       glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
  65.    }
  66. }
  67.  
  68.  
  69.  
  70.  
  71. static void key( unsigned char key, int x, int y )
  72. {
  73.    switch (key) {
  74.       case 27:
  75.          exit(0);
  76.    }
  77. }
  78.  
  79.  
  80.  
  81. /* new window size or exposure */
  82. static void reshape( int width, int height )
  83. {
  84.    glViewport(0, 0, (GLint)width, (GLint)height);
  85. }
  86.  
  87.  
  88. static void init( void )
  89. {
  90.    Image = LoadRGBImage( IMAGE, &ImgWidth, &ImgHeight, &ImgFormat );
  91.    if (!Image) {
  92.       printf("Couldn't read %s\n", IMAGE);
  93.       exit(0);
  94.    }
  95.    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  96. }
  97.  
  98.  
  99.  
  100. int main( int argc, char *argv[] )
  101. {
  102.    glutInitWindowPosition(0, 0);
  103.    glutInitWindowSize(500, 500);
  104.    glutInitDisplayMode( GLUT_RGB );
  105.  
  106.    if (glutCreateWindow("winpos") <= 0) {
  107.       exit(0);
  108.    }
  109.  
  110.    init();
  111.  
  112.    glutReshapeFunc( reshape );
  113.    glutKeyboardFunc( key );
  114.    glutDisplayFunc( draw );
  115.    glutMainLoop();
  116.    return 0;
  117. }
  118.